use std::collections::{BTreeSet, HashMap};

pub struct HuffmanTree {
    left: Box<HuffmanTree>,
    right: Box<HuffmanTree>,
    freq: f64,
}

impl HuffmanTree {
    pub fn from_table(freqs: &[(char, f64)]) -> HuffmanTree {
        todo!("from_table")
    }
    pub fn to_table(&self) -> Vec<(char, f64)> {
        todo!("to freq table")
    }
    pub fn encode(&self, text: &str) -> Vec<i32> {
        let map = self.get_map();
        let mut result: Vec<i32> = vec![];
        for c in text.chars() {
            result.append(&mut map.get(&c).unwrap().clone());
        }
        result
    }
    pub fn decode(&self, bits: &[i32]) -> Box<String> {
        todo!("decode")
    }
    pub fn get_map(&self) -> HashMap<char, Vec<i32>> {
        todo!("get_map")
    }
}

#[test]
fn test_huffman() {
    println!("test huffman tree");
    let freqs = vec![
        ('a', 0.05),
        ('b', 0.15),
        ('c', 0.25),
        ('d', 0.35),
        ('e', 0.45),
    ];
    // let tree = HuffmanTree::from_table(&freqs);
    // let text = "abcdecdcecabaaaabe";
    // let encoded = tree.encode(text);
}
